using System;
using System.Collections.Generic;
using System.Xml;

namespace System.Web.Core
{
    public class ReturnEntity
    {
        private Type entityType = null;
        private EntityReturnMode entityReturnMode = EntityReturnMode.Single;
        private List<ReturnField> returnFieldList = new List<ReturnField>();

        public Type EntityType
        {
            get
            {
                return entityType;
            }
            set
            {
                entityType = value;
            }
        }
        public EntityReturnMode EntityReturnMode
        {
            get
            {
                return entityReturnMode;
            }
            set
            {
                entityReturnMode = value;
            }
        }
        public List<ReturnField> ReturnFieldList
        {
            get
            {
                return returnFieldList;
            }
        }

        public ReturnEntity(XmlNode returnEntityNode)
        {
            this.entityType = Type.GetType(returnEntityNode.Attributes["entityType"].Value);
            this.entityReturnMode = (EntityReturnMode)Enum.Parse(typeof(EntityReturnMode), returnEntityNode.Attributes["entityReturnMode"].Value);

            ReturnField returnField = null;
            foreach (XmlNode returnFieldNode in returnEntityNode.ChildNodes)
            {
                returnField = new ReturnField();
                returnField.PropertyName = returnFieldNode.Attributes.GetNamedItem("propertyName").Value;
                returnField.FieldName = returnFieldNode.Attributes.GetNamedItem("fieldName").Value;
                ReturnFieldList.Add(returnField);
            }
        }
    }
}
